package com.qying.myguava.util;

import java.util.Objects;
import java.util.function.Predicate;

public interface MyPredicate<T> {

    boolean test(T t);

    default MyPredicate<T> and(MyPredicate<? super T> other){
        Objects.requireNonNull(other);
        return (t)->test(t) && other.test(t);
    }

    default MyPredicate<T> negate(){
        return (t)->!test(t);
    }

    default MyPredicate<T> or(Predicate<? super T> other) {
        Objects.requireNonNull(other);
        return (t)->test(t) || other.test(t);
    }

    static <T> MyPredicate isEquals(Object targetRef) {
        return (null == targetRef)
                ? Objects::isNull : object->targetRef.equals(object);
    }
}
